import Vue from 'vue'
import VueRouter from 'vue-router'
// 按需加载路由
const Index=()=>import('../views/index.vue')
const Login=()=>import('../views/Login.vue')
const Home=()=>import('../views/Home.vue')
const Order=()=>import('../views/Order.vue')
const Me=()=>import('../views/Me.vue')
const Address=()=>import('../views/Address')
const City=()=>import('../views/City')
const Search=()=>import('../views/Search')
const Shop=()=>import('../views/Shop/shop.vue')
const Goods=()=>import('../views/Shop/Goods.vue')
const Commit=()=>import('../views/Shop/commit.vue')
const Seller=()=>import('../views/Shop/seller.vue')
const AddAddress=()=>import('../views/Orders/Addaddress.vue')
const MyAddress=()=>import('../views/Orders/Myaddress.vue')
const Settlement=()=>import('../views/Orders/Settlement.vue')
const Remark=()=>import('../views/Orders/remark.vue')
const Pay=()=>import('../views/Orders/Pay.vue')
const OrderInfo=()=>import('../views/Orders/OrderInfo.vue')
Vue.use(VueRouter)

  const routes = [
 {path:'/',component:Index,children:[
	 {path:"",redirect:'/home'},
	 {path:"home",name:"home",component:Home},
	 {path:"order",name:"order",component:Order},
	 {path:"me",name:"me",component:Me},
	 {path:"address",name:"address",component:Address},
	 {path:"city",name:"city",component:City},
 ]},
 {path:'/login',component:Login,name:'login'},
 {path:'/search',component:Search,name:'search'},
 {path:'/shop',component:Shop,name:'shop' ,redirect:"/goods",children:[
	 {path:'/goods',name:"goods",component:Goods},
	 {path:'/commit',name:"commits",component:Commit},
	 {path:'/seller',name:"seller",component:Seller},
	 ]},
	 {path:'/addaddress',component:AddAddress,name:'addaddress'},
	 {path:'/myaddress',component:MyAddress,name:'myaddress'},
	 {path:'/settlement',component:Settlement,name:'settlement'},
	 {path:'/remark',component:Remark,name:'remark'},
	 {path:'/pay',component:Pay,name:'pay'},
	{path:"/orderinfo",name:"orderinfo",component:OrderInfo}
]

const router = new VueRouter({
  mode: 'history',
	linkActiveClass:"active",
  base: process.env.BASE_URL,
  routes
})
//路由守卫
router.beforeEach((to,from,next)=>{
	const isLogin=localStorage.ele_Login?true:false;
	if(to.path==="/login"){
		next();
	}else{
		//是否在登录状态下
		isLogin?next():next("/login");
	}
})
export default router
